home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / language / awe / awe-full.lha / Awe2 / DoNotUseThisSrc / CpuMultiplexor.h < prev    next >
C/C++ Source or Header  |  1990-08-08  |  4KB  |  189 lines

  1. // This may look like C code, but it is really -*- C++ -*-
  2. // 
  3. // Copyright (C) 1988 University of Illinois, Urbana, Illinois
  4. //
  5. // written by Dirk Grunwald (grunwald@cs.uiuc.edu)
  6. //
  7. #ifndef CpuMultiplexor_h
  8. #define CpuMultiplexor_h
  9.  
  10. #ifdef __GNUG__
  11. #  pragma once
  12. #  pragma interface
  13. #endif
  14.  
  15. #include <AwesimeConfig.h>
  16. #include <HardwareContext.h>
  17. #include <CpuMuxExceptions.h>
  18. #include <SpinLock.h>
  19.  
  20. //
  21. //    Define the abstractions for per UNIX process resources.
  22. //
  23.  
  24. #include <ThreadContainer.h>
  25.  
  26. class Thread;
  27. class ReserveByException;
  28. class AwesimeHeap;
  29. class SpinLock;
  30. class SpinFetchAndOp;
  31. class CpuMultiplexor;
  32.  
  33. //
  34. //    Filled in by the single original UNIX process. This value may
  35. //    change during execution
  36. //
  37.  
  38. extern int CpuMultiplexors;
  39. extern CpuMultiplexor *ThisCpu;
  40. extern int CpuMuxDebugFlag;
  41.  
  42. extern SpinLock CpuCerrLock;
  43.  
  44. class CpuMultiplexor {
  45. protected:
  46.  
  47.     friend class SimulationMultiplexor;
  48.     friend class SingleSimMux;
  49.     friend class MultiSimMux;
  50.     friend class MonitorSimMux;
  51.  
  52.     Thread *currentThread;
  53.     HardwareContext systemContext;
  54.  
  55.     ThreadContainer *myCurrentEvents;
  56.     SpinLock *myCurrentEventsLock;
  57.     int *myCurrentEventsCounter;
  58.  
  59.     int iYam;    // I yam what I yam
  60.     int pid;    // ...except to UNIX
  61.  
  62.     char nameSpace[128];
  63.     char *pNameTemplate;
  64.     char *pName;
  65.  
  66.     volatile int *terminated;
  67.     int enabled;
  68.  
  69.     virtual Thread *remove();
  70.     //
  71.     // Constructors of this class and all subclasses should call their
  72.     // own allocateLocalEventStructures, because constructors automatically
  73.     // chain the calls.
  74.     //
  75.     // Use AllocateEventStructures when allocating resources for a CPU and
  76.     // you're not in the constructor. Use deallocateEventStructures for
  77.     // removing those resources. These routines should call subclass
  78.     // instances of the same names.
  79.     //
  80.     //void allocateLocalEventStructures(int,int);
  81.     virtual void allocateEventStructures(int,int);
  82.     virtual void deallocateEventStructures();
  83.  
  84.     //
  85.     // Primarily provided so subclasses, e.g. SimulationMultiplexor,
  86.     // can efficiently add threads without a lot of locking.
  87.     // Note that these are non-virtuals.
  88.     //
  89.     void addUnlocked(Thread *);
  90.  
  91.     //
  92.     //    Exception handlers.
  93.     //
  94.  
  95.     friend class ExceptionReserve;
  96.     friend class ExceptionTerminate;
  97.     friend class ExceptionReschedule;
  98.     friend class ExceptionIveSuspended;
  99.     friend class ExceptionRelocate;
  100.     friend class ExceptionEnrollDismissCpu;
  101.  
  102.     ExceptionClass *raisedBy;
  103.     ExceptionReserve reserveException;
  104.     ExceptionTerminate terminateException;
  105.     ExceptionReschedule rescheduleException;
  106.     ExceptionIveSuspended iveSuspendedException;
  107.  
  108. //
  109. //    Public interfaces for exceptions
  110. //
  111. public:
  112.  
  113.     void raise(ExceptionClass *);
  114.     void reserveByException( ReserveByException * );
  115.     void threadTerminateException( Thread* );
  116.     void flick();
  117.  
  118. public:
  119.     CpuMultiplexor(int debug = 0);
  120.     virtual ~CpuMultiplexor();
  121.  
  122.     virtual void fireItUp(int Cpus = 1, unsigned shared = (4196 * 500));
  123.     virtual void warmThePot(int);
  124.     virtual void stirItAround();
  125.     virtual void coolItDown();
  126.  
  127.     virtual void terminateAll();
  128.  
  129.     virtual void add(Thread *);
  130.  
  131.     Thread * CurrentThread();
  132.  
  133.     void debug(int newdebug);
  134.     int debug();
  135.     const char *name();
  136.  
  137.     int cpuId();
  138. };
  139.  
  140. static inline int
  141. CpuMultiplexor::cpuId()
  142. {
  143.     return( iYam );
  144. }
  145.  
  146. static inline const char *
  147. CpuMultiplexor::name()
  148. {
  149.     return(pName);
  150. }
  151.  
  152. static inline Thread *
  153. CpuMultiplexor::CurrentThread()
  154. {
  155.     return( currentThread );
  156. }
  157.  
  158. //
  159. //    Expansions for exception handling
  160. //
  161. #include <Thread.h>
  162.  
  163. static inline void
  164. CpuMultiplexor::flick()
  165. {
  166.     currentThread -> cpuAffinity = -1;
  167.     raise( &rescheduleException ); 
  168. }
  169.  
  170. static inline Thread *
  171. CurrentThread()
  172. {
  173.     return( ThisCpu -> CurrentThread() );
  174. }
  175.  
  176. static inline void
  177. CheckCurrentStack()
  178. {
  179.     CurrentThread() -> checkStack();
  180. }
  181.  
  182. //
  183. //    These are things the user needs to define
  184. //
  185.  
  186. extern ThreadContainer *AllocateHardwareCurrentEventsStructure();
  187.  
  188. #endif /* CpuMultiplexor_h */
  189.